<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t" id="signupForm" method="post" enctype="multipart/form-data">
		    <input type="hidden" name="id" value="${demandEnterprise.id }" />
		    <input type="hidden" name="status" value="${demandEnterprise.status }" />
		    <div class="form-group form-inline">
				<label class="col-sm-2 control-label">公司名称：</label>
				<div class="col-sm-4">
					<input type="text" name="companyName" id="companyName" class="form-control" placeholder="请选择公司"  onclick="chooseCompany()" readonly="readonly" value="${demandEnterprise.company.name }"/>
				    <input type="hidden" name="companyId" id="companyId" class="form-control" value="${demandEnterprise.companyId }"/>
				    <p class="help-block" style="color: red;">*必填项，请选择单个公司进行操作。</p>
				</div>
				<label class="col-sm-2 control-label">企业联系人：</label>
				<div class="col-sm-4">
					<select class="form-control" id="contact" name="contact">
					
					</select>
					<button type="button" onclick="opencontact();">刷新</button>
					<p class="help-block" style="color: red;">如新增企业联系人，请刷新后选择</p>
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">岗位职能：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="functionalName" name="positionNames" onclick="openTree('functional');" placeholder="请选择岗位"
										readonly="readonly" value="${demandEnterprise.positionNames}"/> 
					<input type="hidden" name="position" id="functionalId" value="${demandEnterprise.position}"/>
				</div>
				<label class="col-sm-2 control-label">岗位名称：</label>
				<div class="col-sm-4"> 
					<input type="text" class="form-control" id="positionName" name="positionName" placeholder="请输入岗位名称" value="${demandEnterprise.positionName}"/>
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">需求人数：</label>
				<div class="col-sm-4 form-inline">
					<input type="text" class="form-control" id="demandNum" name="demandNum" onblur="isInteger('demandNum',this.value);" value="${demandEnterprise.demandNum}"/>(人)
				</div>
				<label class="col-sm-2 control-label">岗位产生原因：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="cause" name="cause"  value="${demandEnterprise.cause}"/>
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">工作区域：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="area1Name" name="workAreaNames" onclick="openTree('area',1);" placeholder="请选择工作区域"
										readonly="readonly" value="${demandEnterprise.workAreaNames}"/> 
					<input type="hidden" name="workArea" id="area1Id" value="${demandEnterprise.workArea}"/>
				</div>
				<label class="col-sm-2 control-label">汇报上级：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="reportSuperiors" name="reportSuperiors"  value="${demandEnterprise.reportSuperiors}"/>
				</div>
			</div>
			<div class="form-group">
			    <label class="col-sm-2 control-label">主要职责：</label>
				<div class="col-sm-9">
					<textarea class="form-control" id="mainDuty" name="mainDuty" >${demandEnterprise.mainDuty}</textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">核心任职要求：</label>
				<div class="col-sm-9">
					<textarea class="form-control" id="coreRequire" name="coreRequire" >${demandEnterprise.coreRequire}</textarea>
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">直接下属：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="underling" name="underling"  value="${demandEnterprise.underling}"/>
				</div>
				<label class="col-sm-2 control-label">年龄区间：</label>
				<div class="col-sm-4 form-inline">
					<input type="text" class="form-control" id="startAge" name="startAge" value="${demandEnterprise.startAge }" onblur="isInteger('startAge',this.value);"/> -
					<input type="text" class="form-control" id="endAge" name="endAge" value="${demandEnterprise.endAge }" onblur="isInteger('endAge',this.value);"/>(岁)
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">最佳年龄：</label>
				<div class="col-sm-4 form-inline">
					<input type="text" class="form-control" id="optimalAge" name="optimalAge"  value="${demandEnterprise.optimalAge}" onblur="isInteger('optimalAge',this.value);"/>(岁)
				</div>
				<label class="col-sm-2 control-label">性别：</label>
				<div class="col-sm-4">
				   <label class="radio-inline"> 
					   <input value="0" name="sex" type="radio" <c:if test="${demandEnterprise.sex eq 0 }">checked="checked" </c:if>> 不限
					</label> 
				   <label class="radio-inline"> 
					   <input value="1" name="sex" type="radio" <c:if test="${demandEnterprise.sex eq 1 }">checked="checked" </c:if>> 男
					</label> 
					<label class="radio-inline">
                          <input value="2" name="sex" type="radio" <c:if test="${demandEnterprise.sex eq 2 }">checked="checked" </c:if>> 女
					</label>
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">学历：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="education" name="education"  value="${demandEnterprise.education}"/>
				</div>
				<label class="col-sm-2 control-label">统招：</label>
				<div class="col-sm-4">
					<label class="radio-inline"> <input value="1"
						 name="unified" type="radio" <c:if test="${demandEnterprise.unified eq 1 }">checked="checked" </c:if>> 是
					</label> <label class="radio-inline"> <input value="2"
						name="unified" type="radio"<c:if test="${demandEnterprise.unified eq 2 }">checked="checked" </c:if> > 否
					</label>
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">薪酬范围：</label>
				<div class="col-sm-4 form-inline">
					<input type="text" class="form-control" id="startSalary" name="startSalary"  value="${demandEnterprise.startSalary }" onblur="isIntDec('startSalary',this.value);"/> -
					<input type="text" class="form-control" id="endSalary" name="endSalary" value="${demandEnterprise.endSalary }" onblur="isIntDec('endSalary',this.value);"/>(万人民币)
				</div>
				<label class="col-sm-2 control-label">薪酬结构：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="salaryStructure" name="salaryStructure"  value="${demandEnterprise.salaryStructure}"/>
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">对标企业经历：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="standardEnterprise" name="standardEnterprise"  value="${demandEnterprise.standardEnterprise}"/>
				</div>
				<label class="col-sm-2 control-label">排除企业工作的人：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="excludePerson" name="excludePerson"  value="${demandEnterprise.excludePerson}"/>
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">排除区域：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control" id="area2Name" name="excludeAreaNames" onclick="openTree('area',2);" placeholder="请选择排除区域"
										readonly="readonly" value="${demandEnterprise.excludeAreaNames}"/> 
					<input type="hidden" name="workArea" id="area2Id"value="${demandEnterprise.excludeArea}"/>
				</div>
			</div>
			<div class="form-group form-inline">
				<label class="col-sm-2 control-label">开始时间：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control Wdate" id="startDate" name="startDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'endDate\')}'})"
										readonly="readonly" value="${demandEnterprise.startDate }"/> 
				</div>
				<label class="col-sm-2 control-label">结束时间：</label>
				<div class="col-sm-4">
					<input type="text" class="form-control Wdate" id="endDate" name="endDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startDate\')}',maxDate:'2120-10-01'})" 
										readonly="readonly" value="${demandEnterprise.endDate }"/> 
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label"> 备注 ：</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" id="remark" name="remark"  value="${demandEnterprise.remark}"/>
				</div>
			</div>
			<div class="form-group form-inline" style="text-align: center;">
				<div class="col-sm-4 col-sm-offset-3">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
	var tops = "${tops}";
    $(function () {
    	 opencontact("${demandEnterprise.companyId}");
    	 $("#sub").click(function () {
    	//批量验证表单非空
		//调用方式
    	var arr=new Array(
    	  new Array('position','岗位名称未填写!'),
    	  new Array('cause','岗位产生原因未填写!'),
    	  new Array('workArea','工作区域未填写!'),
    	  new Array('reportSuperiors','汇报上级未填写!'),
    	  new Array('underling','直接下属未填写!'),
    	  new Array('startAge','年龄区间开始未填写!'),
    	  new Array('endAge','年龄区间结束未填写!'),
    	  new Array('optimalAge','最佳年龄未填写!'),
    	  new Array('sex','性别未填写!'),
    	  new Array('education','学历未填写!'),
    	  new Array('startSalary','薪酬范围开始未填写!'),
    	  new Array('startSalary','薪酬范围结束未填写!'),
    	  new Array('salaryStructure','薪酬结构未填写!'),
    	  new Array('standardEnterprise','对标企业经历未填写!'),
    	  new Array('excludePerson','排除企业工作的人未填写!'),
    	  new Array('excludeArea','排除区域未填写!')
    	)
    	 for(var i=0;i<arr.length;i++){
        	  if($("#"+arr[i][0]).val()==''){
        		  $("#"+arr[i][0]).tips({
  					side:3,
  		            msg:arr[i][1],
  		            bg:'#AE81FF',
  		            time:1
  		        });
        		  $("#"+arr[i][0]).focus();
  				return;
  			}
    	  }
          $("#signupForm").ajaxSubmit({
              url: '<%=contextPath%>/demandEnterprise/update',
              type: 'post',
              dataType: "json",
              success: function (data) {
                  if (data.code == 200) {
                      swal({
                          title: data.message,
                          type: "success",
                          showCancelButton: false,
                          confirmButtonText: "确定",
                          animation: "slide-from-bottom",
                          closeOnConfirm: true
                      }, function () {
                          top.Dialog.close();
                      });
                  } else {
                      swal("错误", data.message, "error");
                  }
              }
          });
    	 });
    });
  //分配资源
	function openTree(obj,num){
		var ids;
		if(typeof(num)=="undefined"){ 
			ids = $("#"+obj+"Id").val();
		}else{
			ids = $("#"+obj+num+"Id").val();
		}  
	   	 var diag = new top.Dialog();
		 diag.Drag=true;
		 diag.Title ="请选择";
		 diag.URL = '<%=contextPath %>/'+obj+'/openZtree?ids='+ids+'&tops='+tops;
		 diag.Width = 250;
		 diag.Height = 400;
		 diag.CancelEvent = function(){ //关闭事件
			 var tempid = diag.innerFrame.contentWindow.document.getElementById('tempids').value;
			 var tempname = diag.innerFrame.contentWindow.document.getElementById('tempnames').value;
			if(tempid.length!==0){
				if(typeof(num)=="undefined"){ 
					$("#"+obj+"Id").val(tempid);
					$("#"+obj+"Name").val(tempname);
				}else{
					$("#"+obj+num+"Id").val(tempid);
					$("#"+obj+num+"Name").val(tempname);
				}
			}
			diag.close();
		 };
		 diag.show();
	}
	function chooseCompany(){
		 var company = $("#companyName").val();
	   	 var diag = new top.Dialog();
		 diag.Drag=true;
		 diag.Title ="请选择公司";
		 diag.URL = '<%=contextPath %>/company/chooseCompnay?companyName='+company+'&tops='+tops;
		 diag.Width = 700;
		 diag.Height = 650;
		 diag.CancelEvent = function(){ //关闭事件
			 var tempid = diag.innerFrame.contentWindow.document.getElementById('tempids').value;
		     console.log("返回id:"+tempid);
			 var tempname = diag.innerFrame.contentWindow.document.getElementById('tempnames').value;
			 console.log("返回name:"+tempname);
			if(tempid.length!==0){
					$("#companyId").val(tempid);
					$("#companyName").val(tempname);
					$.ajax({
		        		url: '<%=contextPath%>/company/getContactBy?companyId='+tempid,
		    			type : 'post',
		    			dataType : "json",
		    			success : function(data) {
		    				if(data.code==400){
		    					swal({
									title : "即将进入企业联系人",
									type : "info",
									showCancelButton : false,
									confirmButtonText : "确定",
									animation : "slide-from-bottom",
									closeOnConfirm : true
								}, function() {
									openyem("添加公司联系人", "<%=contextPath%>/company/addContactView?companyId="+tempid, 600, 750);
								});
							}
		    			}
		        	});
					opencontact(tempid);
			} 
			diag.close();
		 };
		 diag.show();
	}
	function opencontact(id) {
		if(typeof(id) == "undefined"){
			id = $("#companyId").val();
		}
		var contact = "${demandEnterprise.contact}";
		if(id!=''){
			$.ajax({
	    		url: '<%=contextPath%>/company/getContactBy?companyId='+id,
				type : 'post',
				dataType : "json",
				success : function(data) {
					var htm='<option value="">==请选择==</option>';
					if(data.code==200){
						var result = data.contacts;
						for (var i = 0; i < result.length; i++) {
							if(contact == result[i].contactId){
								htm +='<option value="'+result[i].contactId+'" selected>'+result[i].resume.trueName+'/'+result[i].resume.cellphone+'</option>';
							}else {
								htm +='<option value="'+result[i].contactId+'">'+result[i].resume.trueName+'/'+result[i].resume.cellphone+'</option>';
							}
						}
					}
					$("#contact").html(htm);
				}
	    	});
		}else {
			swal({
    			title:"请选择公司",
    			text: "2秒后自动关闭。", 
    			timer: 2000, 
			    showConfirmButton: false
    		});
		}
		
	}
</script>
</body>
</html>